package cn.com.guanying.android.ui.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.com.guanying.R;
import cn.com.guanying.javacore.v11.models.AreaInfo;
import cn.com.guanying.javacore.v11.models.CinemaInfo;

public class CinemaAdapter extends BaseExpandableListAdapter {

	private ArrayList<AreaInfo> mCinemas = new ArrayList<AreaInfo>();
	private Context mContext;
	private LayoutInflater mLayoutInflater;
	public CinemaAdapter(Context context){
		mContext = context;
		mLayoutInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	public int getGroupCount() {
		return mCinemas == null ? 0 : mCinemas.size();
	}

	public int getChildrenCount(int groupPosition) {
		if (mCinemas == null || mCinemas.size() <= groupPosition)
			return 0;
		AreaInfo area = mCinemas.get(groupPosition);
		return area.getmCinemas() == null ? 0 : area.getmCinemas().size();
	}

	public Object getGroup(int groupPosition) {
		if (mCinemas == null || mCinemas.size() <= groupPosition)
			return null;
		return mCinemas.get(groupPosition);
	}

	public Object getChild(int groupPosition, int childPosition) {
		if (mCinemas == null || mCinemas.size() <= groupPosition)
			return null;
		AreaInfo area = mCinemas.get(groupPosition);
		if (area == null)
			return null;
		ArrayList<CinemaInfo> temCinema = area.getmCinemas();
		if (temCinema == null || temCinema.size() <= childPosition)
			return null;
		return temCinema.get(childPosition);
	}

	public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
		LinearLayout area = (LinearLayout)mLayoutInflater.inflate(R.layout.item_area_list, null);
//		TextView areaName = (TextView)area.findViewById(R.id.cinema_area);
//		areaName.setText("");
		return area;
	}

	public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
		if(convertView==null)
			convertView = (LinearLayout)mLayoutInflater.inflate(R.layout.item_cinema_list, null);
		return convertView;
	}

	public long getGroupId(int groupPosition) {
		return groupPosition;
	}

	public long getChildId(int groupPosition, int childPosition) {
		return childPosition;
	}

	public boolean hasStableIds() {
		return false;
	}

	public boolean isChildSelectable(int groupPosition, int childPosition) {
		return true;
	}

	public void setmCinemas(ArrayList<AreaInfo> mCinemas) {
		this.mCinemas = mCinemas;
	}

}
